<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 除了返回数据，yield 还可以接收从外部传入的值。通过 next(value) 方法，可以将一个值传递到 yield 处：
    function* gen() {
        const a = yield "Enter a number: ";
        console.log(`Received value: ${a}`);
    }

    const g = gen();
    console.log(g.next().value);  // 输出: "Enter a number: "
    console.log(g.next(10).value);  // 输出: "Received value: 10"

</script>
</html>